package com.bwt.top.bwt_ad_flutter.view.widget;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bwt.top.bwt_ad_flutter.ad.BwtServiceAd;
import com.bwt.top.bwt_ad_flutter.manager.BwtServiceAdManager;
import com.bwt.top.bwt_ad_flutter.model.AdParams;

import io.flutter.plugin.platform.PlatformView;

public class BwtServiceAdWidget implements PlatformView {
    private FrameLayout adContainer;
    public BwtServiceAdWidget(@NonNull Context context, @NonNull AdParams adParams){
        BwtServiceAdManager manager = BwtServiceAdManager.getInstance();
        BwtServiceAd ad = manager.getBwtServiceAdMap().get(adParams.getAdId());
        this.adContainer = ad.getAdContainer();
//        this.adContainer = new FrameLayout(context);

    }

    @Nullable
    @Override
    public View getView() {

        return this.adContainer;
    }

    @Override
    public void dispose() {
        release();
    }
    public void release() {
        try {
            if (this.adContainer != null) {
                this.adContainer.removeAllViews();
                this.adContainer = null;
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
